package com.zyx.mpdemo.helpers.utils;

import com.zyx.mpdemo.model.entity.Course;
import com.zyx.mpdemo.model.vo.CourseCost;
import com.zyx.mpdemo.model.vo.CourseDetailVO;

import java.util.List;
import java.util.stream.Collectors;

/**
 * <p>课程统计工具类
 *
 * @author Yaxi.Zhang
 * @since 2022/11/21 14:23
 */
public class CourseStatisticsUtils {

    /**
     * 依据课程列表获取课程时间
     */
    public static CourseCost getCourseCost(List<Course> courses) {
        List<CourseCost> courseCostList = courses.stream()
                .map(it -> new CourseCost().setHours(it.getCourseHours()).setMinutes(it.getCourseMinutes()).setSeconds(it.getCourseSeconds()))
                .collect(Collectors.toList());
        return CourseCost.fromList(courseCostList);
    }

    public static double getLearnedPercentage(CourseCost learnedCourse, CourseCost allCourse) {
        return learnedCourse.getCourseSeconds() * 1.0 / allCourse.getCourseSeconds();
    }

}
